//
//  DynameicLoginView.m
//  SameWorld(merchant)
//
//  Created by 李小朋 on 2017/4/18.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "DynameicLoginView.h"
#import <Masonry.h>
@implementation DynameicLoginView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup {

    self.backgroundColor = [UIColor colorWithHexString:@"f2f2f2"];
    
    UIView *backView = [[UIView alloc] initWithFrame:(CGRectMake(0, 10, size_width, 90))];
    backView.backgroundColor = [UIColor whiteColor];
    [self addSubview:backView];
    
    // 手机图片
    UIImageView *phoneImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shouji"]];
    [backView addSubview:phoneImage];
    
    // 验证码图片
    UIImageView *validationImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mima"]];
    [backView addSubview:validationImage];
    
    // 手机号码
    UITextField *userName = [[UITextField alloc] init];
    userName.placeholder = @"请输入手机号";
    userName.clearButtonMode = UITextFieldViewModeAlways;
    userName.font = [UIFont systemFontOfSize:12];
    userName.textColor = color_textTwo;
    userName.clearButtonMode = UITextFieldViewModeAlways;
    [backView addSubview:userName];
    self.userPhone = userName;
    
    // 短信验证码
    UITextField *verificationCode = [[UITextField alloc] init];
    verificationCode.placeholder = @"请输入短信验证码";
    verificationCode.font = [UIFont systemFontOfSize:12];
    verificationCode.textColor = color_textTwo;
    verificationCode.clearButtonMode = UITextFieldViewModeAlways;
    [backView addSubview:verificationCode];
    self.verificationCode = verificationCode;
    
    // 发送验证码
    UIButton *sendCodeBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [sendCodeBtn setTitle:@"发送验证码" forState:(UIControlStateNormal)];
    [sendCodeBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    sendCodeBtn.backgroundColor = [UIColor colorWithHexString:@"#ff9900"];
    sendCodeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    sendCodeBtn.layer.masksToBounds = YES;
    sendCodeBtn.layer.cornerRadius = 2.0f;
    [sendCodeBtn addTarget:self action:@selector(sendCodeBtnClick:) forControlEvents:(UIControlEventTouchUpInside)];
    [backView addSubview:sendCodeBtn];
    self.sendCodeBtn = sendCodeBtn;
    
    // 分割线线条
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor colorWithHexString:@"#dddddd"];
    [backView addSubview:lineView];
    
    // 底部线条
    UIView *bottomView = [[UIView alloc] init];
    [backView addSubview:bottomView];
    
    // 提交按钮
    UIButton *submitBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [submitBtn setTitle:@"确认提交" forState:(UIControlStateNormal)];
    [submitBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    submitBtn.backgroundColor = [UIColor colorWithHexString:@"#ff9900"];
    submitBtn.alpha = 0.6;
    submitBtn.layer.masksToBounds = YES;
    submitBtn.layer.cornerRadius = 2.0f;
    [submitBtn addTarget:self action:@selector(submitBtnClick:) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:submitBtn];
    
    // 设置手机图片约束
    [phoneImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(12);
        make.top.offset(15);
        make.width.height.offset(14);
    }];
    
    // 设置用户手机号约束
    [userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(phoneImage.mas_right).offset(12);
        make.right.offset(-12);
        make.top.offset(0);
        make.height.offset(44);
    }];
    
    // 设置分割线约束
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(userName.mas_bottom).offset(0);
        make.height.offset(1);
        make.left.equalTo(phoneImage.mas_right).offset(12);
        make.right.offset(0);
    }];
    
    // 设置验证码图片约束
    [validationImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(12);
        make.top.equalTo(lineView.mas_bottom).offset(15);
        make.width.height.offset(14);
    }];
    // 设置短信验证码约束
    [verificationCode mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(validationImage.mas_right).offset(12);
        make.top.equalTo(lineView.mas_bottom).offset(0);
        make.width.offset(120);
        make.height.offset(44);
    }];

    // 设置发送验证码约束
    [sendCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-12);
        make.top.equalTo(lineView.mas_bottom).offset(8);
        make.width.offset(84);
        make.height.offset(28);
        
    }];
 
    
    // 设置底部线条约束
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(verificationCode.mas_bottom).offset(0);
        make.height.offset(1);
        make.left.offset(0);
        make.right.offset(0);
    }];
    // 设置提交按钮约束
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backView.mas_bottom).offset(36);
        make.left.offset(12);
        make.right.offset(-12);
        make.height.offset(44);
    }];
    
}

#pragma mark - 发送验证码
- (void)sendCodeBtnClick:(UIButton *)sender {
    
    self.sendCodeBtnClick();
}

#pragma mark - 确认提交
- (void)submitBtnClick:(UIButton *)sender {

    self.submitBtnClick();
}


@end
